Dashboarding for Leaders and Managing Data in Shiny

R Gov Conference

2024-10-28

Workshop Goals

By the end of this workshop, participants will leave with:

  1. Functional Shiny application templates.
  2. An understanding of
    • Shiny reactivity
    • Functions & Modules in Shiny
    • Dashboard design principles
    • Calendars using {timevis}
    • CRUD apps in R and Shiny
  3. A network of peers for collaboration.
  4. Enhanced skills in R and Shiny.

To Get the Most Out of This Workshop

  1. Latest version of R (Version 4.3.1)

  2. Latest version of RStudio (Version 2023.09.0+463)

  3. Git experience

  4. Basic R Shiny knowledge

  5. Knowledge of your organization’s needs

Workshop Agenda Overview

  • 8:00 AM - 8:50 AM: Welcome, Introductions & Setup
  • 9:00 AM - 10:00 AM: Block 1 - Shiny Reactivity
  • 10:15 AM - 11:15 AM: Block 2 - Functions & Modules in Shiny
  • 11:30 AM - 12:30 PM: Block 3 - Dashboard Design Principles
  • 12:30 PM - 1:30 PM: Lunch
  • 1:30 PM - 2:30 PM: Block 4 - Calendar Module
  • 2:45 PM - 3:45 PM: Block 5 - CRUD apps in R and Shiny
  • 4:00 PM - 5:00 PM: Block 6 - Advanced Techniques & Hands-On

Instructors

Instructor

MAJ Maxine Drake

 

Assistant

LTC Dusty Turner

Maxine Drake: Instructor Introduction

  • Engineer Officer
    • Platoon Leader: North Carolina (and Afghanistan)
    • Company Commander: Leesville, LA
  • Operations Research Systems Analyst (ORSA)
    • Center for Army Analysis, Fort Belvoir, VA
    • Futures & Concepts Center, Fort Eustis, VA

Maxine Drake: Instructor Introduction

  • Education
    • BS Economics & Russian, United States Military Academy
    • MS Operations Research, George Mason University
  • Personal
    • Married to Nate with 3 kids: Charlotte (9), Tommy (5), and Mikey (3)

Dusty Turner: Assistant Introduction

  • Engineer Officer
    • Platoon Leader: Hawaii (Iraq)
    • Company Commander: White Sands Missile Range, NM (Afghanistan)
  • Assistant Professor / Instructor
    • United States Military Academy, West Point, NY
  • Operations Research Systems Analyst (ORSA)
    • Center for Army Analysis, Fort Belvoir, VA

Dusty Turner: Assistant Introduction

  • Education
    • BS Operations Research, United States Military Academy
    • MS Engineering Management, University of Missouri of Science and Technology
    • MS Integrated Systems Engineering, The Ohio State University
    • Applied Statistics Minor
    • Doctoral Candidate, Baylor University, Statistics (Expected 2025)
  • Personal
    • Married to Jill (2010)
    • Children: Cal (2013) and Reese (2015)

Class Introductions

Let’s go around the room for quick introductions:

  1. Name
  2. Organization
  3. Current role
  4. Experience level with R and Shiny
  5. What you hope to achieve from this workshop

Block 1: Shiny Reactivity

9:00 AM - 10:00 AM

Shiny Reactivity

Mastering Shiny by Hadley Wickham

Reactive Functions

reactiveVal() to set a single reactive value

v <- shiny::reactiveVal(0)
v()  # 0
v(2) # 2


reactiveValues() to create an object for storing (multiple) reactive values

v <- shiny::reactiveValues(item1 = "abc", item2 = tibble())
v$item1 # "abc"
v$item2 # A tibble: 0 × 0

v$item1 <- "Go Army!"

reactive({}) to create reactive expressions

reactive_table <- reactive({head(mtcars, input$number)})


eventReactive({}) and observeEvent({}) to handle events (e.g., button click, input selected)

reactive_string <- shiny::eventReactive(input$button, {
  paste0("user selected ", input$selection)
})
reactive_string() # "user selected APPLES"

observeEvent(input$button, {
  write_csv(x = v$item2, file = "file_name.csv")
})
v <- reactiveValues(ingredients = read_latest_ingredients_file(),
                    staples = read_latest_staples_file())

ingredients_category <- reactive({
  v$ingredients %>%
    filter(Category != "") %>%
    pull(Category) %>%
    unique()
  })

output$ingredient_edit_table <- renderRHandsontable({
  rhandsontable(v$ingredients) %>%
    hot_col("Category", source = category())
})

v$ingredients <- eventReactive(input$submit_ingredients, {
     hot_to_r(input$ingredient_edit_table)
  })

Shiny Reactivity

Now, we’ll open R_Workshop/04_tutorial_reactives/app_reactives.R and work from there.

Break

Block 2: Functions & Modules in Shiny

10:15 AM - 11:15 AM

Functions & Modules in Shiny

Mastering Shiny by Hadley Wickham

Functions & Modules in Shiny

Now, we’ll open R_Workshop/05_tutorial_modules/app_modules.R and work from there.

Break

Block 3: Dashboard Design Principles

11:30 AM - 12:30 AM

Dashboard Design Principles

Effective dashboard design ensures that the audience can quickly absorb critical information and make informed decisions. Here are the key principles:

1. Understand the Purpose, Audience and Context

2. Simple & Clear Visual Elements

  • Opt for simple and effective visualizations.
  • Too many graphs or charts = cognitive overload.
  • Consider interactivity so the user can explore.

Dashboard Design Principles


3. Prioritization of Information
  • Ensure that decision-making data is accessible at a glance.
  • Use size, position, and color to draw attention to key metrics.


4. Balance Timely Data against Speed of App
  • Minimize data operations within app session
  • Maximize user’s ability to see timely data
  • What does “Timely Data” mean for you projects?

Dashboard Design Principles


5. Consistency
  • Consistent formatting, fonts, and color schemes.
  • Consistent types of charts for similar types of data to foster familiarity.


6. Accessibility
  • Ensure the dashboard is easy to use, even for individuals who may not be highly technical.
  • Use color contrast and design elements that are accessible to all users, including those with visual impairments.
  • Provide tooltips or brief explanations for more complex metrics.

Dashboard Design Principles

Resources

  • “The Visual Display of Quantitative Information” by Edward Tufte A classic, emphasizing clarity, precision, and efficiency in visualizing data.

  • “Information Dashboard Design: Displaying Data for At-a-Glance Monitoring” by Stephen Few Guidelines for creating clear and actionable dashboards that allow users to quickly grasp insights.

  • 8 Essential Dashboard Design Principles for Effective Data Visualization

Lunch Break

12:30 PM - 1:30 PM

Block 4: Calendars in Shiny

1:30 PM - 2:30 PM

Calendars in Shiny

  • {timevis}: Allows you to build interactive timelines in Shiny or Quarto. It is based on the ‘vis.js’ Timeline JavaScript library.

Break

Block 5: CRUD Apps in R and Shiny

2:45 PM - 3:45 PM

CRUD Apps in R and Shiny

CRUD stands for Create, Read, Update, and Delete. A CRUD app allows users to view and manage data.

Start with your logical model

Design CRUD tables

CRUD Apps in R and Shiny

Check out R_workshop/app.R

  • Use {rhandsontable}, {reactable}, or {DT} to display selectable/editable tables
  • Control user submissions through shiny::actionButtons
  • Validate user input using functions, such as shiny::req, shiny::validate, shinyfeedback::feedback, and shiny::showNotification
  • A CRUD app could have the following key steps:
    1. Read in data
    2. Join and transform data into user table(s), using a function
    3. Make your user table to a reactive object, using reactiveValues
    4. Upon user submission, there are two subprocesses: 1) Transform submission back into original raw table structure, using a function, then write to data, and 2) Update your reactive user table with submission

Break

Block 6: Advanced Techniques & Hands-on Exercises

4:00 PM - 4:45 PM

Advanced Techniques & Hands-on Exercises

Summary & Wrap-Up

4:45 Pm - 5:00PM